USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0002_CODIGOS_SEGUROS]    Script Date: 11/24/2011 14:15:27 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WASP_M0002_CODIGOS_SEGUROS]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[WASP_M0002_CODIGOS_SEGUROS]
GO

USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0002_CODIGOS_SEGUROS]    Script Date: 11/24/2011 14:15:27 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[WASP_M0002_CODIGOS_SEGUROS] 
AS 
BEGIN
	SELECT	a.ppcta
			,a.ppoper
			,a.ppsuc
			,a.ppimp11
			,a.ppimp12
			,a.ppimp13
			,a.ppimp14
			,a.ppimp15
			,a.ppimp16
			,a.ppimp17
			,a.ppimp18
			,a.ppimp19
	INTO	codigos_seguros
	FROM	fsd611 AS a
			,fsd601 AS b  
	WHERE	--a.ppoper = 100000109
			-- AND a.ppsuc = 11
			a.pptipo = ''
	AND		a.ppexte = 9
	AND		a.pgcod = b.pgcod 
	AND		a.ppmod = b.ppmod 
	AND		a.ppsuc = b.ppsuc 
	AND 	a.ppmda = b.ppmda 
	AND		a.ppcta = b.ppcta 
	AND 	a.ppoper = b.ppoper 
	AND		a.ppsbop = b.ppsbop 
	AND		a.pptope = b.pptope
	AND		b.d601co = 'S'
	GROUP BY a.ppsuc, a.ppcta, a.ppoper, a.ppimp11, a.ppimp12,
			 a.ppimp13, a.ppimp14, a.ppimp15, a.ppimp16,
			 a.ppimp17, a.ppimp18, a.ppimp19
END

GO


